package com.pj.main;

import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) {
        final String serverHost = "192.168.88.128"; // 服务端IP地址
        final int serverPort = 8193; // 服务端端口号

        try {
            // 创建客户端 Socket，连接到服务端
            Socket clientSocket = new Socket(serverHost, serverPort);
            System.out.println("连接到服务端");

            // 创建输出流，向服务端发送数据
            OutputStream outputStream = clientSocket.getOutputStream();
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));

            int count = 0;
            while (true) {
                String data = "数据" + count; // 模拟采集的数据
                writer.write(data);
                writer.newLine();
              //  writer.flush();
                System.out.println("发送数据: " + data);

                Thread.sleep(1000); // 每隔1秒采集一次数据

                count++;
            }

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}